DROP DATABASE GT;
CREATE DATABASE GT;
USE GT
GO
CREATE TABLE Documents(
	DocumentID UNIQUEIDENTIFIER PRIMARY KEY NOT NULL,
	DocumentPath NVARCHAR(400) NOT NULL,
	CONSTRAINT UK_DocumentPath UNIQUE(DocumentPath)
);
CREATE TABLE Nodes(
	NodeID UNIQUEIDENTIFIER PRIMARY KEY NOT NULL,
	NodeText NVARCHAR(50) NOT NULL,
	NumDocument INT NOT NULL DEFAULT 0,
	ParentID UNIQUEIDENTIFIER NOT NULL,
	CONSTRAINT UK_NodeText_ParentID UNIQUE(NodeText, ParentID)	
);
INSERT INTO Nodes VALUES('AF810092-98D2-41FA-AA0B-2C5804474B6E', '/', 0, 'AF810092-98D2-41FA-AA0B-2C5804474B6E');
ALTER TABLE Nodes ADD CONSTRAINT FK_ParentID_NodeID FOREIGN KEY(ParentID) REFERENCES Nodes(NodeID);
CREATE INDEX IDX_Nodes_NodeText_ParentID ON Nodes(NodeText, ParentID);